<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户登录</title>
<script type="text/javascript" src="/lib/jquery/jquery-1.3.2.min.js"></script>
<link href="/lib/css/business.css" type="text/css" rel="stylesheet"/> 
</head>
<body>
<!-- 登录div -->
	<div class="login" id="login">
		<div class="fr_login">
			<img style="float:right;" onclick="hideLogin();" src="/lib/images/business/close.png"/>
			<br/>
			<div style="display:inline;">
			<form action="" method="post">
				<table>
					<tbody>
						<tr>
							<td style="width:100px;">用户名：</td>
							<td><input type="text" placeholder="手机或邮箱" id="name" name="name" value="" /></td>
							<td></td>
						</tr>
						<tr>
							<td>密码：</td>
							<td><input type="password" placeholder="密码" id="password" name="password" value="" /></td>
							<td></td>
						</tr>
						<tr>
							<td>验证码：</td>
							<td><input type="text" placeholder="验证码" id="code" name="code" value="" style="width:10" /></td>
							<td><img src="/getCode" id="getCode" class="pointer" onclick="doRefCode();"/></td>
						</tr>
						<tr>
							<td></td>
							<td>点这里<a href="/toRegister">注册</a></td>
							<td><span id="error" style="color:red;"></span></td>
						</tr>
						<tr>
							<td></td>
							<td>
								<input type="reset" name="" value="重置"/>
								<input type="button" id="button" onclick="loginSubmit();" value="登录"/>
							</td>
							<td></td>
						</tr>
					</tbody>
				</table>
			</form>
			</div>
		</div>
	</div>

</body>
<script type="text/javascript">
//刷新验证码
function doRefCode(){
	$("#getCode").attr("src","/getCode?"+Math.random());
}
$('.login').fadeIn("10");
function hideLogin(){
	window.history.go(-1);
}
function loginSubmit(){
	var name = $('#name').val();
	var password = $('#password').val();
	var code = $('#code').val();
	if(name == ''){
		alert('请输入帐户');
		return;
	}
	if(password == ''){
		alert('请输入密码');
		return;
	}
	if(code == ''){
		alert('请输入验证码，查看下一张请点击验证码图片刷新');
		return;
	}
	var remember = $('#remember').val();
	$.ajax({
		type: 'post',
		data: {'name':name,'password':password,'code':code,'remember':remember},
		dataType: 'json',
		asycn: true,
		url: '/loginSubmit',
		success: function(data, status){
			if(data.msg == 'success'){
				var url = data.lastURL;
				if(url == ''){
					url = "/";
				}
				window.parent.location = url;
			}else{
				//刷新当前页面
				//window.parent.location.reload();
				doRefCode();
				$('#code').val('');
				$('#password').val('');
				$('#error').html(data.msg);
			}
		},
		error: function(XMLHttpRequest, textStatus, thrownError){
			alert("错误"+textStatus);
		}
	}); 
}
$(document).keydown(function (e){
	if (e.keyCode == 13){
		loginSubmit();
	}
});	
</script>
</html>